﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace SplendidCRM.Ext.Models
{
    public class GridViewModel : GridViewModel<dynamic, dynamic>
    {
        private DynamicDataModel _params;
        public override dynamic Params
        {
            get { return _params ?? (_params = new DynamicDataModel()); }
            set { _params = new DynamicDataModel(Mvc.GetRouteValues(value)); }
        }
    }

    public class GridViewModel<TParam> : GridViewModel<dynamic, TParam>
    {
    }

    [Naming(NamingStyle.CamelCase)]
    public class GridViewModel<TEntity, TParams>
    {

        public Int32 CurrentPage { get; set; }
        public Int32 PageSize { get; set; }
        public Int32 PageCount { get; set; }
        public Int32 TotalItems { get; set; }
        public IEnumerable<SortExpression> SortBy { get; set; }
        public virtual TParams Params { get; set; }

        private TEntity[] _items;
        public IEnumerable<TEntity> Items
        {
            get { return _items; }
            set { _items = (value ?? new TEntity[0]).ToArray(); }
        }
    }

    [Naming(NamingStyle.CamelCase)]
    public class SortExpression
    {
        public String Column { get; set; }
        public Boolean Desc { get; set; }
    }
}